<?php

namespace app\admin\model\cms;
use app\admin\model\cms\Plate;
use think\Model;
use traits\model\SoftDelete;


class Platepost extends Model
{
    // 表名
    protected $name = 'plate_post';

    //软删除
    use SoftDelete;

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [
        'is_audit_text',
        'block_text'
    ];
    public function getIsAuditTextAttr($value, $data)
    {
        return $data['is_audit'] ==1 ? '通过': '未通过';
    }
    public function getBlockTextAttr($value, $data)
    {
        $value = $value ? $value : $data['plateid'];
        $name  = Plate::where('id', '=', $value)->value('platename'); 
        return !empty($name) ? $name:'';
    }
    
    public function block()
    {
        return $this->belongsTo('Plate', 'plateid', '', [], 'LEFT')->setEagerlyType(0);
    }

    public function user(){
        return $this->belongsTo('app\admin\model\User', 'user_id', 'id', [], 'LEFT')->field('id,username,nickname,avatar,bio,email')->setEagerlyType(1);
    }

    public function category()
    {
        return $this->belongsTo('app\admin\model\cms\Plate', 'plateid', 'id', [], 'LEFT')->setEagerlyType(0);
    }






}
